<template>
  <div class="editForm-wrapper">
    <el-dialog class="tableDialog" :title="title" :close-on-click-modal="false" v-dialogDrag :visible.sync="visible" width="952px">
        <div class="header">
            <p>{{truckNumber}}</p>
        </div>

      <div class="title">
        <p>当前车主</p>
      </div>
        <el-form label-width="112px" :model="viewForm" ref="viewForm" v-loading="loading">
            <el-row class="multiple">
            <el-form-item label="车主姓名:" prop="owerName">
                <el-input v-model="viewForm.owerName" :disabled="true"></el-input>
            </el-form-item>
                <el-form-item label="车主手机号码:" prop="owerPhone">
                    <el-input v-model=" viewForm.owerPhone" :disabled="true"></el-input>
                </el-form-item>

            </el-row>
            <el-row class="multiple">
                <el-form-item label="车主证件号:" prop="owerIdcard">
                    <el-input v-model="viewForm.owerIdcard" :disabled="true"></el-input>
                </el-form-item>
                <el-form-item label="绑定时间:" prop="owerDate">
                    <el-input v-model="viewForm.owerDate" :disabled="true"></el-input>
                </el-form-item>
            </el-row>
        </el-form>
        <div class="title">
          <p>历史车主</p>
        </div>
      <el-table size="mini" v-loading="loading" :data="tableData" style="width: 100%; margin-top: 10px" border
        :header-cell-style="{
        'background-color': '#eeeeee !important',
      }" :row-class-name="tableRowClassName">
        <el-table-column type="index" label="序号" width="60" align="center">
          <template slot-scope="scope">
            <span>{{
            (page.pageNo - 1) * page.pageSize + scope.$index + 1
          }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="ower.names" label="姓名" width="120">
        </el-table-column>
        <el-table-column prop="ower.contactPhone" label="手机号" width="150">
        </el-table-column>
        <el-table-column prop="ower.idCard" label="证件号码" min-width="200">
        </el-table-column>
        <el-table-column prop="createDate" label="绑定时间" width="200">
        </el-table-column>
      </el-table>
      <el-pagination background @current-change="handleCurrentChange" :page-size="page.pageSize" :current-page="page.pageNo"
        layout="total,prev, pager, next" :total="page.total">
      </el-pagination>
    </el-dialog>
  </div>
</template>

<script>
  export default {
    data() {
      return {
        title: '',
        method: '',
        visible: false,
        loading: false,
        tableData: [],
        truckId: '',
        truckNumber: '',
        viewForm: {
          id: '',
          owerName: '',
          owerPhone: '',
          owerIdcard: '',
          addressId: '',
          owerId: '',
          owerDate: ''
        },
        page: {
          pageSize: 5,
          pageNo: 1,
          total: 0
        }
      }
    },
    methods: {
      init(method, obj) {
        this.method = method
        this.title = '查看车主'
        this.viewForm = obj
        this.visible = true
        this.loading = false
        this.truckId = obj.id
          this.truckNumber = obj.truckNumber
        this.refreshList(this.page)
      },
      // 获取数据列表
      refreshList (params) {
        this.loading = true
        this.$http({
          url: '/truck/ower/hislist',
          method: 'get',
          params: {
            'pageNo': params.pageNo,
            'pageSize': params.pageSize,
            'truck.id': this.truckId,
            'notOwerId':this.viewForm.owerId
          }
        }).then(({
          data
        }) => {
          if (data.code === '200') {
            this.tableData = data.result.list
            this.page.total = data.result.count
            this.loading = false
          }
        })
      },
      handleCurrentChange (e) {
        this.page.pageNo = e
        this.refreshList(this.page, this.truckId)
      },
      tableRowClassName ({
        row,
        rowIndex
      }) {
        if (rowIndex % 2 === 1) {
          return 'warning-row'
        } else {
          return 'success-row'
        }
      }
    }
  }
</script>
<style lang="scss" scoped>
  .editForm-wrapper {
      p{
          margin: 0;
      }
    ::v-deep.el-dialog {
      .el-input__inner {
        width: 320px !important;
      }
        .el-dialog__body{
            .header{
                margin-bottom: 20px;
                p{
                    font-size: 24px;
                    font-family: Microsoft YaHei;
                    font-weight: bold;
                    color: #333333;
                    text-align: center;
                }
            }
            .title{
                height: 40px;
                line-height: 40px;
                background: #F8F8F8;
                font-size: 16px;
                font-family: Microsoft YaHei;
                font-weight: 400;
                color: #333333;
                padding-left: 19px;
            }
            .el-form{
                margin-top: 20px;
                .el-row.multiple{
                    display: flex;
                    .el-form-item:first-child{
                        margin-right: 30px;
                    }
                }
            }
        }
      .el-dialog__body .el-form .el-form-item {
        margin-bottom: 20px !important;
        margin-right: 0;
      }
    }
  }
  .view-container {
    margin-bottom: 20px;
    display: flex;
    .label-container {
      width: 150px;
      text-align: right;
      font-size: 16px;
      font-weight: 400;
      color: #666666;
    }
    .form-container {
      font-size: 14px;
      font-weight: 400;
      color: #333333;
      width: 200px;
    }
    .title {
      position: absolute;
      left: 19%;
      width: 200px;
      margin: 1 auto;
      line-height: 24px;
      font-size: 20px;
    }
  }
</style>
